﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace JasRibbonApplicatie.Converters
{
    class SourceListConverter:IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null && value is string)
                return (value as string).Split(';').ToList();
            else
                return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string r ="";
            if (value != null)
            {
                try
                {
                    var list = (List<string>) value;
                    r = String.Join(";",list);
                }
                catch (InvalidCastException ex)
                {
                    Console.WriteLine("SourceListConverter.cs ConvertBack exeption:" + ex.ToString());
                }
            }
            return r;
        }

        #endregion
    }
}
